page.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. 'use server';
  2. import View from './view';
  3. import { notFound, forbidden, redirect } from 'next/navigation';
  4. import { BoardLayout } from '@/constants/forum';
  5. import { isAuthenticated } from '@/lib/api/auth';
  6. import { fetchBoard } from '@/lib/api/forum/board';
  7. import { fetchPostData } from '@/lib/api/forum/post';
  8. export default async function PostView({ params }: { params: Promise<{ id: string }> })
  9. {
  10. const { id } = await params;
  11. if (!/^\d+$/.test(id)) {
  12. return forbidden();
  13. }
  14. // 게시글 정보 조회
  15. const post = await fetchPostData(Number(id));
  16. if (!post.ok || !post.data) {
  17. return notFound();
  18. }
  19. // 게시판 조회
  20. const board = await fetchBoard(post.data.boardCode);
  21. if (!board || !board.data) {
  22. return notFound();
  23. }
  24. if (!board.data.isActive) {
  25. return forbidden();
  26. }
  27. const boardMeta = board.data.boardMeta;
  28. // 1:1 게시판은 로그인한 사용자만 접근 가능
  29. if (boardMeta.list.layout === BoardLayout.QnA && !await isAuthenticated()) {
  30. redirect('/login');
  31. }
  32. return (
  33. <View _board={board.data} _post={post.data} />
  34. );
  35. }